﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Model;
using System.Configuration;
using System.Data;

namespace TCDC_System
{
    public partial class Default : System.Web.UI.Page
    {
        Model.Login objLogin;

        protected void Page_Load(object sender, EventArgs e)
        {
            objLogin = new Model.Login();
            objLogin.strConn = ConfigurationManager.AppSettings["ConnString"];
        }

        protected void btLogin_Click(object sender, DirectEventArgs e)
        {

            DataTable dt = objLogin.verifyLogin(txtUser.Text, txtPassword.Text);
            Ext.Net.X.Js.AddScript("window.location = '../Content/Default.aspx';");
            //if (dt.Rows.Count == 1)
            //{
            //    Ext.Net.X.Js.AddScript("window.location = '../Content/Default.aspx';");
            //}
            //else
            //{
            //    //ERROR
            //    X.Msg.Show(new MessageBoxConfig
            //    {
            //        Buttons = MessageBox.Button.OK,
            //        Icon = MessageBox.Icon.ERROR,
            //        Title = "Login Fail",
            //        Message = "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง<br>กรุณาตรวจสอบอีกครั้ง"
            //    });


            //    txtUser.Text = "";
            //    txtPassword.Text = "";
            //    txtUser.AutoFocus = true;
            //}


            //if(txtUser.Text !="" && txtPassword.Text !="")
            //{
            //    Ext.Net.X.Js.AddScript("window.location = '../Content/Default.aspx';");
            //}
            //else
            //{
            //    //ERROR
            //    X.Msg.Show(new MessageBoxConfig
            //    {
            //        Buttons = MessageBox.Button.OK,
            //        Icon = MessageBox.Icon.ERROR,
            //        Title = "Login Fail",
            //        Message = "ชื่อผู้ใช้งานหรือรหัสผ่านไม่ถูกต้อง<br>กรุณาตรวจสอบอีกครั้ง"
            //    });


            //    txtUser.Text = "";
            //    txtPassword.Text = "";
            //    txtUser.AutoFocus = true;
            //}
        }
        protected void btCancel_Click(object sender, DirectEventArgs e)
        {
            txtUser.Text = "";
            txtPassword.Text = "";
        }

        protected void MessageWarning(String message)
        {
            X.Msg.Show(new MessageBoxConfig
            {
                Title = "Warning Message",
                Message = message,
                Buttons = MessageBox.Button.OK,
                Icon = (MessageBox.Icon)Enum.Parse(typeof(MessageBox.Icon), "WARNING"),
            });
        }

    }
}